﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

namespace 健康码管理系统
{
    public partial class Add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sql = "insert into UserInfo( Name, IdCard, PhoneNumber, Sex, Age, CreateDate, CId, State)" +
                "values(@Name, @IdCard, @PhoneNumber, @Sex, @Age, @CreateDate, @CId, @State)";
            using (SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=123456;database=Test2;")) {
                using (SqlCommand command=new SqlCommand(sql,conn)) {
                    command.Parameters.AddWithValue("Name",txtName.Text );
                    command.Parameters.AddWithValue("IdCard",txtId.Text);
                    command.Parameters.AddWithValue("PhoneNumber",txtPhone.Text);
                    command.Parameters.AddWithValue("Sex",txtSex.Text);
                    command.Parameters.AddWithValue("Age",txtAge.Text);
                    command.Parameters.AddWithValue("CreateDate",DateTime.Now.ToString("yyyy-MM-dd"));
                    command.Parameters.AddWithValue("CId",txtJiankang.Text);
                    command.Parameters.AddWithValue("State",txtUp.Text);

                    conn.Open();
                    int result =command.ExecuteNonQuery();
                    if (result > 0) {
                      //  Response.Redirect("~/Selection.aspx");
                        Response.Write("<script>alert('添加成功');window.location='Selection.aspx';</script>");
                    }
                    else {

                        Response.Write("<script>alert('添加失败');</script>");
                    }
                    conn.Close();
                }

            }
        }
    }
}